import QueryMaterial2 from "@/components/QueryMaterial2";
import { s_getSelectData, s_getStockInfo, s_operateInfo, s_stockIn, status2text } from "@/services/basis";
import { ActionType, EditableFormInstance, EditableProTable, ProCard, ProColumns, ProForm, ProFormDatePicker, ProFormDateRangePicker, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from "@ant-design/pro-components";
import { Button ,Col,Divider,Image, message, Modal, Row, Space, Tag} from "antd";
import moment from "moment";
import { useEffect, useRef, useState } from "react";

const App:React.FC=()=>{
     const [total,setTotal]=useState(0);
    interface DataType{
        // id,x_id,warehouse_id,material_id,userdefine_id,userdefine_name,
        // quantity,track_order_type,track_order_did,batch_code,quantity_islock,
        // code,name,invstd,invstd2,munit_name,pic,warehouse_name
        rid?:number,
        id?:number,x_id?:number,warehouse_id?:number,material_id?:number,userdefine_id?:string,userdefine_name?:string,
        quantity?:number,track_order_type?:number,track_order_did?:number,batch_code?:string,quantity_islock?:number,
        code?:string,name?:string,invstd?:string,invstd2?:string,munit_name?:string,pic?:string,
        warehouse_name?:string,pos_name?:string,cate_name?:string,vendor_name?:string,
    };

    const columns:ProColumns<DataType>[]=[
        {dataIndex:'rid',hidden:true,search:false},
        {dataIndex:'pic',title:'图片' ,editable:false,width:60,search:false,
        //     render:(text)=>{
        //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
        //         return <Image src={pic}  
        //                style={{width:50,height:50}} alt='无' />
        //    },
        //  },
        render:(text,record,index,k)=>{
                       var pic="/basis_api/file/get2?filename="+record.code;
                       return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          } 
        },
        {dataIndex:'warehouse_name',title:'仓库',width:100}, 
        {dataIndex:'cate_name',title:'商品分类',width:100},
         {dataIndex:'code',title:'SKU',width:100},{dataIndex:'name',title:'名称',width:100},
         {dataIndex:'invstd',title:'包装规格',search:false},{dataIndex:'vendor_name',title:'供应商',width:100},
        //  {dataIndex:'userdefine_name',title:'自定义项'},
         {dataIndex:'munit_name',title:'单位',search:false},
         {dataIndex:'pos_name',title:'库位',search:false,},
         {dataIndex:'quantity',title:'总库存数',search:false},
         {dataIndex:'quantity_islock',title:'已占用数',search:false},
         {dataIndex:'quantity_isfree',title:'可用数',search:false},
        //  {dataIndex:'track_order_type',title:''},{dataIndex:'track_order',title:''},
        
    ];

     
//   ===================================================================================================
    return <>
         <ProCard title='现存量查询' style={{height:'76vh',overflow:'auto'}}
            //  extra={<Space>
            //     <Button>查询</Button>
            //  </Space>}
         >
              <ProTable<DataType>
                  
                  search={{span:4}}
                  options={false}
                  columns={columns}
                  rowKey='rid'
                  request={async (param)=>{
                    const x=await s_getStockInfo({source:'v_stock_current',x_id:1,
                                   fdata:{id:0,param}});
                    setTotal(x.data[0][0].count);               
                    return{
                        data:x.data[1],
                        success:true,
                    }
                  }}
                   scroll={{y:'50vh'}}
                    pagination={{
                    showQuickJumper:true,
                    showSizeChanger:true,
                    defaultPageSize:10,
                    defaultCurrent:1,
                    total,
                  }}
                />
         </ProCard>
         
        </> ;
}

export default App;